<?php
/**
 * Dependency abstract rank filter
 *
 * PHP version 5
 *
 * @category  W
 * @package   Services
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id:$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
require_once 'W/Dependency/Filter/Abstract.php';
/**
 * Dependency abstract rank filter
 *
 * @category  W
 * @package   Services
 * @author    Olivier Hoareau <olivier@phppro.fr>
 * @copyright 2009 PHPPRO http://www.phppro.fr
 * @license   http://dev.phppro.fr/license PHPPRO
 * @version   SVN: $Id$
 * @link      http://dev.phppro.fr/projects/wdependency
 */
abstract class W_Dependency_Filter_Rank_Abstract extends W_Dependency_Filter_Abstract
{
    public function filter($data)
    {
        $data = $data['data'];
        $list = array();
        foreach($data as $node=>$items) {
            $value = 0;
            foreach($items as $subNode=>$weight) {
                $value+=$weight;
            }
            $list[$node] = $value;
        }
        $list = $this->sortList($list,$data);
        $keptData = array();
        foreach(array_keys($list) as $item) {
            $keptData[$item] = $data[$item];
        }
        return $keptData;
    }
    public abstract function sortList($list,$data);
}